package org.guajava.service.impl;

import org.springframework.stereotype.Service;
import org.guajava.common.exception.BusinessException;
import org.guajava.common.support.Convert;
import org.guajava.common.utils.StringUtils;
import org.guajava.domain.SysConfigInfo;
import org.guajava.domain.SysPost;
import org.guajava.mapper.SysConfigInfoMapper;
import org.guajava.service.ISysConfigService;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysConfigServiceImpl implements ISysConfigService {
    @Resource
    private SysConfigInfoMapper configInfoMapper;
    /**
     * 删除参数信息
     * @param ids
     * @return
     */
    @Override
    public int deleteByPrimaryKey(String ids) {
        Long[] configInfoIds = Convert.toLongArray(ids);

        return configInfoMapper.deleteConfigInfoByIds(configInfoIds);

    }

    /**
     * 新增参数信息
     * @param record
     * @return
     */
    @Override
    public int insert(SysConfigInfo record) {
        return configInfoMapper.insert(record);
    }

    /**
     * 新增参数信息
     * @param record
     * @return
     */
    @Override
    public int insertSelective(SysConfigInfo record) {
        return configInfoMapper.insertSelective(record);
    }
    /**
     * 查询参数信息 byID
     * @param configId
     * @return
     */
    @Override
    public SysConfigInfo selectByPrimaryKey(Integer configId) {
        return configInfoMapper.selectByPrimaryKey(configId);
    }

    /**
     * 修改参数信息
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(SysConfigInfo record) {
        return configInfoMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 修改参数信息
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKey(SysConfigInfo record) {
        return configInfoMapper.updateByPrimaryKey(record);
    }

    /**
     * 查询参数信息列表
     * @param sysConfigInfo
     * @return
     */
    @Override
    public List<SysConfigInfo> selectConfigList(SysConfigInfo sysConfigInfo) {
        return configInfoMapper.selectConfigList(sysConfigInfo);
    }


    /**
     * 根据键名查询参数配置信息
     *
     * @param configKey 参数key
     * @return 参数键值
     */
    @Override
    public String selectConfigByKey(String configKey)
    {
        SysConfigInfo config = new SysConfigInfo();
        config.setConfigKey(configKey);
        SysConfigInfo retConfig = configInfoMapper.selectConfig(config);
        return StringUtils.isNotNull(retConfig) ? retConfig.getConfigValue() : "";
    }



}
